<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数据看板系统 - 首页</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
  <style>
    /* 全局样式 - 科技感设计 */
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      font-family: "Microsoft YaHei", Arial, sans-serif;
    }
    
    body {
      background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
      padding: 20px;
      color: #e2e8f0;
      min-height: 100vh;
    }
    
    .container {
      max-width: 1200px;
      margin: 0 auto;
      background: rgba(15, 23, 42, 0.8);
      padding: 30px;
      border-radius: 16px;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
      backdrop-filter: blur(10px);
      border: 1px solid rgba(94, 234, 212, 0.2);
    }
    
    header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 30px;
      padding-bottom: 20px;
      border-bottom: 1px solid rgba(94, 234, 212, 0.3);
    }
    
    .logo {
      display: flex;
      align-items: center;
      gap: 15px;
    }
    
    .logo-icon {
      width: 50px;
      height: 50px;
      background: linear-gradient(135deg, #0ea5e9 0%, #0d9488 100%);
      border-radius: 12px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 24px;
      color: white;
      box-shadow: 0 0 15px rgba(56, 189, 248, 0.5);
    }
    
    .logo-text {
      font-size: 28px;
      font-weight: 700;
      color: #f8fafc;
      text-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
    }
    
    .logo-text span {
      color: #5eead4;
    }
    
    .nav-buttons {
      display: flex;
      gap: 15px;
    }
    
    .nav-button {
      background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
      color: white;
      padding: 12px 25px;
      border-radius: 8px;
      text-decoration: none;
      font-weight: 600;
      box-shadow: 0 4px 15px rgba(124, 58, 237, 0.4);
      transition: all 0.3s ease;
      display: flex;
      align-items: center;
      gap: 8px;
      border: 1px solid rgba(167, 139, 250, 0.3);
    }
    
    .nav-button:hover {
      transform: translateY(-3px);
      box-shadow: 0 6px 20px rgba(124, 58, 237, 0.6);
      background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
    }
    
    .nav-button.active {
      background: linear-gradient(135deg, #5b21b6 0%, #4338ca 100%);
    }
    
    .page-title {
      text-align: center;
      font-size: 36px;
      margin: 20px 0 40px;
      background: linear-gradient(90deg, #8b5cf6, #0ea5e9, #10b981);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      position: relative;
    }
    
    .page-title::after {
      content: '';
      position: absolute;
      bottom: -10px;
      left: 50%;
      transform: translateX(-50%);
      width: 150px;
      height: 3px;
      background: linear-gradient(90deg, #8b5cf6, #0ea5e9, #10b981);
      border-radius: 3px;
    }
    
    /* 首页样式 */
    .dashboard {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
      gap: 25px;
      margin-top: 30px;
    }
    
    .dashboard-card {
      background: linear-gradient(135deg, rgba(30, 41, 59, 0.7) 0%, rgba(15, 23, 42, 0.9) 100%);
      padding: 25px;
      border-radius: 16px;
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
      text-align: center;
      transition: all 0.3s ease;
      display: flex;
      flex-direction: column;
      align-items: center;
      border: 1px solid rgba(94, 234, 212, 0.1);
      position: relative;
      overflow: hidden;
    }
    
    .dashboard-card::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 4px;
      background: linear-gradient(90deg, #8b5cf6, #0ea5e9, #10b981);
    }
    
    .dashboard-card:hover {
      transform: translateY(-5px);
      box-shadow: 0 10px 25px rgba(56, 189, 248, 0.3);
      border-color: rgba(94, 234, 212, 0.3);
    }
    
    .dashboard-card h3 {
      font-size: 22px;
      margin-bottom: 15px;
      color: #f8fafc;
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 10px;
    }
    
    .dashboard-card p {
      color: #94a3b8;
      line-height: 1.6;
      margin-bottom: 20px;
      width: 100%;
      min-height: 60px;
      font-size: 15px;
    }
    
    .stat-value {
      font-size: 42px;
      font-weight: 800;
      color: #5eead4;
      margin: 15px 0;
      display: block;
      text-shadow: 0 0 10px rgba(94, 234, 212, 0.3);
      font-family: 'Arial', sans-serif;
    }
    
    .stat-label {
      color: #94a3b8;
      font-size: 16px;
      margin-bottom: 20px;
    }
    
    .card-icon {
      font-size: 48px;
      margin-bottom: 15px;
      background: linear-gradient(135deg, #0ea5e9 0%, #0d9488 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
    
    /* 三个主要功能卡片的按钮样式 */
    .dashboard-card:not(:last-child) .nav-button {
      padding: 10px 20px;
      font-size: 16px;
      margin-top: auto;
      background: linear-gradient(135deg, #0ea5e9 0%, #0d9488 100%);
      box-shadow: 0 4px 10px rgba(14, 165, 233, 0.3);
    }
    
    .dashboard-card:not(:last-child) .nav-button:hover {
      background: linear-gradient(135deg, #38bdf8 0%, #14b8a6 100%);
      box-shadow: 0 6px 15px rgba(56, 189, 248, 0.4);
    }
    
    /* 页脚样式 */
    footer {
      text-align: center;
      margin-top: 50px;
      padding-top: 20px;
      color: #64748b;
      font-size: 14px;
      border-top: 1px solid rgba(94, 234, 212, 0.1);
    }
    
    /* 响应式设计 */
    @media (max-width: 768px) {
      header {
        flex-direction: column;
        gap: 20px;
        text-align: center;
      }
      
      .nav-buttons {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
      }
      
      .page-title {
        font-size: 28px;
        margin: 10px 0 25px;
      }
      
      .page-title::after {
        width: 100px;
      }
    }

    /* 排行榜样式 - 固定表格大小 */
    .tabs {
      display: flex;
      justify-content: center;
      margin: 20px 0;
      gap: 15px;
    }
    
    .tab-button {
      background: linear-gradient(135deg, #4a044e 0%, #312e81 100%);
      color: white;
      border: none;
      padding: 16px 32px;
      border-radius: 30px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.3s;
      box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
      font-size: 18px;
      border: 1px solid rgba(139, 92, 246, 0.3);
    }
    
    .tab-button.active {
      background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
      box-shadow: 0 4px 15px rgba(124, 58, 237, 0.6);
    }
    
    .tab-button:hover {
      transform: translateY(-3px);
      box-shadow: 0 6px 15px rgba(124, 58, 237, 0.4);
    }
    
    .ranking-container {
      margin-top: 20px;
      width: 100%;
      min-width: 600px;
    }
    
    .ranking-tab {
      display: none;
      width: 100%;
    }
    
    .ranking-tab.active {
      display: block;
    }
    
    /* 固定排行榜表格布局 */
    .ranking-list {
      width: 100%;
      display: table;
      table-layout: fixed;
      border-collapse: separate;
      border-spacing: 0 8px;
    }
    
    .ranking-item {
      display: table-row;
    }
    
    .rank-number, .rank-name, .rank-value {
      display: table-cell;
      vertical-align: middle;
      padding: 15px;
      background: rgba(30, 41, 59, 0.7);
    }
    
    .rank-number {
      width: 15%;
      height: 40px;
      border-radius: 8px 0 0 8px;
      font-weight: bold;
      font-size: 20px;
      text-align: center;
      color: #5eead4;
      border-left: 3px solid;
    }
    
    .rank-name {
      width: 60%;
      font-weight: 600;
      font-size: 18px;
      color: #f1f5f9;
    }
    
    .rank-value {
      width: 25%;
      font-weight: bold;
      font-size: 20px;
      color: #5eead4;
      text-align: right;
      border-radius: 0 8px 8px 0;
      padding-right: 25px;
    }
    
    /* 确保每一行都有相同的样式容器 */
    .ranking-item-container {
      display: table-row-group;
    }
    
    .rank-1 .rank-number { 
      border-left-color: #fde047; 
      color: #fde047;
    }
    .rank-2 .rank-number { 
      border-left-color: #cbd5e1; 
      color: #cbd5e1;
    }
    .rank-3 .rank-number { 
      border-left-color: #f97316; 
      color: #f97316;
    }
    
    .spinner {
      width: 50px;
      height: 50px;
      border: 5px solid rgba(56, 189, 248, 0.2);
      border-top: 5px solid #0ea5e9;
      border-radius: 50%;
      animation: spin 1s linear infinite;
      margin: 30px auto;
    }
    
    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }

    /* 厅名管理区域样式 */
    .hall-management {
      margin-top: 50px;
      padding-top: 30px;
      border-top: 1px solid rgba(94, 234, 212, 0.1);
      width: 100%;
    }
    
    .hall-management h3 {
      margin-bottom: 20px;
      color: #f8fafc;
      font-size: 24px;
      display: flex;
      align-items: center;
      gap: 15px;
    }
    
    .hall-management h3 i {
      color: #0ea5e9;
      font-size: 28px;
    }
    
    .hall-form {
      display: flex;
      gap: 15px;
      margin-bottom: 20px;
    }
    
    .hall-form input {
      flex-grow: 1;
      padding: 16px 22px;
      background: rgba(15, 23, 42, 0.7);
      border: 1px solid rgba(94, 234, 212, 0.2);
      border-radius: 8px;
      font-size: 18px;
      color: #e2e8f0;
      box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    }
    
    .hall-form input:focus {
      outline: none;
      border-color: #0ea5e9;
      box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.3);
    }
    
    .hall-form button {
      background: linear-gradient(135deg, #10b981 0%, #0d9488 100%);
      color: white;
      border: none;
      padding: 0 28px;
      border-radius: 8px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.3s ease;
      display: flex;
      align-items: center;
      gap: 10px;
      font-size: 18px;
      box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
    }
    
    .hall-form button:hover {
      transform: translateY(-2px);
      box-shadow: 0 6px 15px rgba(16, 185, 129, 0.4);
      background: linear-gradient(135deg, #34d399 0%, #14b8a6 100%);
    }
    
    .hall-list {
      display: flex;
      flex-wrap: wrap;
      gap: 15px;
      margin-top: 15px;
    }
    
    .hall-tag {
      background: rgba(56, 189, 248, 0.15);
      color: #5eead4;
      padding: 12px 22px;
      border-radius: 20px;
      font-size: 18px;
      display: flex;
      align-items: center;
      gap: 10px;
      box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
      border: 1px solid rgba(94, 234, 212, 0.2);
    }
    
    .hall-tag button {
      background: none;
      border: none;
      color: #94a3b8;
      cursor: pointer;
      font-size: 18px;
      font-weight: bold;
      padding: 0 3px;
      transition: color 0.3s;
    }
    
    .hall-tag button:hover {
      color: #f87171;
    }
    
    .notification {
      position: fixed;
      bottom: 20px;
      right: 20px;
      padding: 15px 25px;
      background: linear-gradient(135deg, #10b981 0%, #0d9488 100%);
      color: white;
      border-radius: 8px;
      box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
      transform: translateY(100px);
      opacity: 0;
      transition: all 0.3s ease;
      z-index: 1000;
      display: flex;
      align-items: center;
      gap: 10px;
    }
    
    .notification.show {
      transform: translateY(0);
      opacity: 1;
    }

    .notification.error {
      background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    }

    /* 查看完整排行榜按钮样式 */
    .ranking-container .nav-button {
      padding: 16px 32px;
      font-size: 18px;
      margin: 20px auto;
      display: table;
      background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
    }

    /* 错误提示样式 */
    .error-message {
      color: #f87171;
      text-align: center;
      padding: 20px;
      font-size: 18px;
      background: rgba(248, 113, 113, 0.1);
      border-radius: 8px;
      border-left: 4px solid #f87171;
    }
    
    /* 状态指示灯 */
    .status-indicator {
      display: inline-block;
      width: 12px;
      height: 12px;
      border-radius: 50%;
      margin-right: 8px;
    }
    
    .status-online {
      background-color: #10b981;
      box-shadow: 0 0 8px #10b981;
    }
    
    .status-offline {
      background-color: #f87171;
    }
    
    .connection-status {
      position: fixed;
      bottom: 20px;
      left: 20px;
      padding: 8px 16px;
      background: rgba(15, 23, 42, 0.9);
      border-radius: 20px;
      font-size: 14px;
      display: flex;
      align-items: center;
      border: 1px solid rgba(94, 234, 212, 0.2);
    }
  </style>
</head>
<body>
  <div class="container">
    <header>
      <div class="logo">
        <div class="logo-icon"><i class="fas fa-chart-network"></i></div>
        <div class="logo-text">数据<span>看板</span>系统</div>
      </div>
      <div class="nav-buttons">
        <a href="index.html" class="nav-button active"><i class="fas fa-home"></i> 首页</a>
        <a href="upload.html" class="nav-button"><i class="fas fa-cloud-upload-alt"></i> 数据上传</a>
        <a href="query.html" class="nav-button"><i class="fas fa-search"></i> 数据查询</a>
        <a href="ranking.html" class="nav-button"><i class="fas fa-trophy"></i> 排行榜</a>
      </div>
    </header>
    
    <h1 class="page-title">数据看板概览</h1>
    
    <div class="dashboard">
      <!-- 数据卡片部分 -->
      <div class="dashboard-card">
        <div class="card-icon"><i class="fas fa-cloud-upload-alt"></i></div>
        <h3>数据上传</h3>
        <p>上传日期时间，厅名，主持人，数据，数据截图，大头数据，大头数据截图，主持-厅名</p>
        <span class="stat-value" id="todayRecords">加载中...</span>
        <span class="stat-label">今日新增记录</span>
        <a href="upload.html" class="nav-button"><i class="fas fa-upload"></i> 上传数据</a>
      </div>
      
      <div class="dashboard-card">
        <div class="card-icon"><i class="fas fa-database"></i></div>
        <h3>数据总览</h3>
        <p>系统内所有数据记录的总览分析，包括厅、主持人和数据的统计信息</p>
        <span class="stat-value" id="totalRecords">加载中...</span>
        <span class="stat-label">总数据记录</span>
        <a href="query.html" class="nav-button"><i class="fas fa-chart-bar"></i> 查看数据</a>
      </div>
      
      <div class="dashboard-card">
        <div class="card-icon"><i class="fas fa-users"></i></div>
        <h3>活跃主持人</h3>
        <p>本周有数据上传的主持人数量统计，展示最活跃的主持人群体</p>
        <span class="stat-value" id="activeHosts">加载中...</span>
        <span class="stat-label">本周活跃主持人</span>
        <a href="ranking.html" class="nav-button"><i class="fas fa-user-friends"></i> 查看详情</a>
      </div>

      <!-- 排行榜区域 -->
      <div class="dashboard-card" style="grid-column: 1 / -1; margin-top: 30px;">
        <div class="card-icon"><i class="fas fa-trophy"></i></div>
        <h2>实时排行榜</h2>
        <div class="tabs">
          <button class="tab-button active" data-type="hall">厅排名</button>
          <button class="tab-button" data-type="host">主持排名</button>
        </div>
        
        <div class="ranking-container">
          <div class="ranking-tab active" id="hall-ranking">
            <div class="ranking-list" id="hallRankingList">
              <div class="spinner"></div>
            </div>
          </div>
          <div class="ranking-tab" id="host-ranking">
            <div class="ranking-list" id="hostRankingList">
              <div class="spinner"></div>
            </div>
          </div>
        </div>
        
        <div style="text-align: center; margin-top: 20px;">
          <a href="ranking.html" class="nav-button">
            <i class="fas fa-external-link-alt"></i> 查看完整排行榜
          </a>
        </div>

        <!-- 厅名管理区域 -->
        <div class="hall-management">
          <h3><i class="fas fa-building"></i> 厅名管理</h3>
          <div class="hall-form">
            <input type="text" id="newHallName" placeholder="输入新厅名，例如：OLG·氙氙">
            <button id="addHallBtn"><i class="fas fa-plus"></i> 添加厅名</button>
          </div>
          <div class="hall-list" id="hallList">
            <!-- 厅名列表将从数据库加载 -->
          </div>
        </div>
      </div>
    </div>
    
    <footer>
      <p>数据看板系统 © 2023 | 实时数据监控与分析平台</p>
      <p style="margin-top: 8px; font-size: 13px; color: #64748b;">版本 2.1.0 | 最后更新: 2025-08-06</p>
    </footer>
  </div>

  <!-- 通知提示框 -->
  <div class="notification" id="notification">
    <i class="fas fa-check-circle"></i>
    <div>数据已刷新</div>
  </div>
  
  <!-- 连接状态指示器 -->
  <div class="connection-status" id="connectionStatus">
    <span class="status-indicator status-online"></span>
    <span>后端服务已连接</span>
  </div>

  <script>
    const API_BASE_URL = 'http://localhost:3000/api';
    
    document.addEventListener('DOMContentLoaded', function() {
      // 初始化页面数据
      loadStats();
      loadRankings();
      loadHallList();
      initHallManagement();
      
      // 标签切换
      document.querySelectorAll('.tab-button').forEach(button => {
        button.addEventListener('click', function() {
          document.querySelectorAll('.tab-button').forEach(btn => btn.classList.remove('active'));
          document.querySelectorAll('.ranking-tab').forEach(tab => tab.classList.remove('active'));
          
          this.classList.add('active');
          const type = this.dataset.type;
          document.getElementById(`${type}-ranking`).classList.add('active');
        });
      });
      
      // 模拟WebSocket连接
      simulateWebSocket();
    });
    
    // 模拟WebSocket连接和数据更新
    function simulateWebSocket() {
      const notification = document.getElementById('notification');
      const connectionStatus = document.getElementById('connectionStatus');
      const statusIndicator = connectionStatus.querySelector('.status-indicator');
      
      // 初始显示连接状态
      setTimeout(() => {
        notification.innerHTML = '<i class="fas fa-plug"></i> <div>已连接到后端服务</div>';
        notification.classList.add('show');
        
        setTimeout(() => {
          notification.classList.remove('show');
        }, 3000);
      }, 1000);
      
      // 模拟数据更新
      setInterval(() => {
        // 更新统计数据
        loadStats();
        loadRankings();
        
        // 显示通知
        notification.innerHTML = '<i class="fas fa-sync-alt"></i> <div>数据已自动刷新</div>';
        notification.classList.add('show');
        
        setTimeout(() => {
          notification.classList.remove('show');
        }, 3000);
      }, 30000);
    }
    
    // 加载统计数据
    async function loadStats() {
      try {
        // 获取今日新增记录
        const todayRes = await fetch(`${API_BASE_URL}/data/query?startDate=${new Date().toISOString().split('T')[0]}&endDate=${new Date().toISOString().split('T')[0]}`);
        const todayData = await todayRes.json();
        document.getElementById('todayRecords').textContent = todayData.totalCount;
        
        // 获取总记录数
        const totalRes = await fetch(`${API_BASE_URL}/data/query`);
        const totalData = await totalRes.json();
        document.getElementById('totalRecords').textContent = totalData.totalCount;
        
        // 获取活跃主持人数量
        const activeRes = await fetch(`${API_BASE_URL}/hosts/active`);
        const activeData = await activeRes.json();
        document.getElementById('activeHosts').textContent = activeData.count;
      } catch (error) {
        console.error('加载统计数据失败:', error);
      }
    }
    
    // 加载排行榜数据
    async function loadRankings() {
      try {
        // 加载厅排名
        const hallRes = await fetch(`${API_BASE_URL}/ranking?type=hall&range=week`);
        const hallData = await hallRes.json();
        renderRanking('hallRankingList', hallData);
        
        // 加载主持人排名
        const hostRes = await fetch(`${API_BASE_URL}/ranking?type=host&range=week`);
        const hostData = await hostRes.json();
        renderRanking('hostRankingList', hostData);
      } catch (error) {
        console.error('加载排行榜数据失败:', error);
      }
    }
    
    // 渲染排行榜
    function renderRanking(elementId, data) {
      const container = document.getElementById(elementId);
      
      if (!data || data.length === 0) {
        container.innerHTML = `
          <div class="empty-state" style="text-align: center; padding: 30px;">
            <i class="fas fa-trophy" style="font-size: 40px; color: #64748b; margin-bottom: 15px;"></i>
            <p>暂无排名数据</p>
          </div>
        `;
        return;
      }
      
      let html = '';
      data.forEach((item, index) => {
        const name = item.hallName || item.hostName;
        const value = item.totalValue || item.dataValue;
        html += `
          <div class="ranking-item rank-${index + 1}">
            <div class="rank-number">${index + 1}</div>
            <div class="rank-name">${name}</div>
            <div class="rank-value">${Number(value).toLocaleString()}</div>
          </div>
        `;
      });
      
      container.innerHTML = html;
    }
    
    // 加载厅名列表
    async function loadHallList() {
      try {
        const response = await fetch(`${API_BASE_URL}/data/halls`);
        let halls = await response.json();
        

        
        renderHallList(halls);
        return halls;
      } catch (error) {
        console.error('加载厅名列表失败:', error);

      }
    }
    
    // 渲染厅名列表
    function renderHallList(halls) {
      const hallList = document.getElementById('hallList');
      hallList.innerHTML = '';
      
      halls.forEach(hall => {
        const hallTag = document.createElement('div');
        hallTag.className = 'hall-tag';
        hallTag.innerHTML = `
          ${hall.hall_name}
          <button class="delete-hall" data-hall="${hall.hall_name}" data-id="${hall.id}">&times;</button>
        `;
        hallList.appendChild(hallTag);
      });
      
      // 添加删除事件
      document.querySelectorAll('.delete-hall').forEach(button => {
        button.addEventListener('click', async function() {
          const hallToDelete = this.getAttribute('data-hall');
          const id = this.getAttribute('data-id');
          await deleteHall(id);
        });
      });
    }
    
    // 初始化厅名管理功能
    function initHallManagement() {
      const addHallBtn = document.getElementById('addHallBtn');
      const newHallInput = document.getElementById('newHallName');
      
      addHallBtn.addEventListener('click', async function() {
        const hallName = newHallInput.value.trim();
        if (!hallName) {
          showNotification('请输入厅名', true);
          return;
        }
        
        // 检查是否已存在
        const halls = await loadHallList();
        if (halls.includes(hallName)) {
          showNotification('该厅名已存在', true);
          return;
        }
        
        // 添加新厅名
        const newHalls = [...halls, hallName];
        await saveHallsToServer(hallName);
 
        
        newHallInput.value = '';
       
      });
      
      // 支持回车键添加
      newHallInput.addEventListener('keypress', function(e) {
        if (e.key === 'Enter') {
          addHallBtn.click();
        }
      });
    }
    
    // 保存厅名到服务器
    async function saveHallsToServer(halls) {
      try {
        const response = await fetch(`${API_BASE_URL}/data/halls`, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json'
          },
          body: JSON.stringify({ hallName: halls })
        });
        showNotification(`厅名 添加成功`);
        if (!response.ok) throw new Error('保存厅名失败');
        loadHallList();
        return true;
      } catch (error) {
        console.error('保存厅名失败:', error);
        showNotification('保存厅名失败', true);
        return false;
      }
    }
    
    // 删除厅名
    async function deleteHall(id) {
      try {
        const response = await fetch(`${API_BASE_URL}/data/halls/${id}`, {
          method: 'DELETE',
          headers: {
            'Content-Type': 'application/json'
          },
          body: JSON.stringify({ id: id })
        });

        if (!response.ok) throw new Error('删除厅名失败');
        showNotification(`厅名 删除成功`);
        loadHallList();
        return true;
      } catch (error) {
        console.error('删除厅名失败:', error);
        showNotification('删除厅名失败', true);
        return false;
      }
      
    }
    
    // 显示通知
    function showNotification(message, isError = false) {
      const notification = document.getElementById('notification');
      notification.innerHTML = `
        <i class="fas ${isError ? 'fa-exclamation-circle' : 'fa-check-circle'}"></i>
        <div>${message}</div>
      `;
      
      if (isError) {
        notification.classList.add('error');
      } else {
        notification.classList.remove('error');
      }
      
      notification.classList.add('show');
      
      setTimeout(() => {
        notification.classList.remove('show');
      }, 3000);
    }
  </script>
</body>
</html>